<?php
set_time_limit(0);

date_default_timezone_set('Etc/GMT-8'); 

$pages = 292;

$link = mysql_connect('localhost', 'root', '111111') or die("Could not connect: " . mysql_error());
mysql_select_db("zhaoren");
mysql_query('SET NAMES utf8');

for($i=20; $i < $pages; $i++)
{
	//<dl><dt><a href="http://baotou.edeng.cn/jiedaoxinxi/55865134.html"
	$contents = file_get_contents("http://www.edeng.cn/15/xunrenwang-tupian/$i");
	preg_match_all("/<dt><a href=\"(.+?)\"/", $contents, $match);
	
	$sql = 'INSERT IGNORE INTO collect_search_info (email, subject, name, notice, collect_url, collect_date) VALUES (';
	
	if($match[1])
	{
		foreach($match[1] as $url)
		{
			$info_contents = file_get_contents($url);
	
			//邮件
			preg_match("/<li class=\"email\">(.+?@[^<]+)/", $info_contents, $match_email);
			
			//print_r($match_email);exit;
			
			if(isset($match_email[1]) && $match_email[1] )
			{
				$email = trim(str_replace("&nbsp;", '', $match_email[1]));
				//$info['id'] = $id;			
				//$info['email'] = $email;
				
				//主题
				preg_match("/<div class=\"headline left\">.+?title=\"(.+?)\"/is", $info_contents, $match_subject);
				$subject = trim($match_subject[1]);
				//$info['subject'] = $subject;
		
				//姓名
				//<li class="jiaoyouwidth"><i>名字：</i>赵斌</li>
				preg_match("/<i>名字：<\/i>([^<]+?)<\/li>/is", $info_contents, $match_name);
				$name = trim($match_name[1]);
				//$info['name'] = $name;
				
				//内容
				//<p style="clear:both;">2011-9-18 18:36:42
				preg_match("/<p style=\"clear:both;\">(.+?)<\/p>/is", $info_contents, $match_notice);
				$notice = trim(strip_tags($match_notice[1]));
				//$info['notice'] = $notice;
				
				$collect_date	= date('Y-m-d H:i:s', time());
				$sql_value		= "'".$email."', '".$subject."', '".$name."', '".$notice."', '".trim($url)."', '".$collect_date."')";

				mysql_query($sql.$sql_value);
		
				//$collect_info[] = $info;
				unset($sql_value);
				
				sleep(1);
			}
		}
	}
}

//print_r($collect_info);

//insert ignore into 
//echo $contents;

?>